package com.briup.service.impl;

import com.briup.exception.ServiceException;
import com.briup.response.ResultCode;
import com.briup.service.UploadService;
import com.briup.utils.UploadUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@Service
public class UploadServiceImpl implements UploadService {

	@Resource
	private UploadUtils uploadUtils;

	@Override
	public String upload(MultipartFile file) {
		String url = null;
		try {
			//上传到本地nginx服务器
			// url = uploadUtils.fileToLocal(file);
			//上传到七牛云服务器
			url = uploadUtils.fileToOSS(file);
		} catch (Exception e) {
			log.info("文件上传失败,原因:{}", e.getMessage());
			throw new ServiceException(ResultCode.SYSTEM_INNER_ERROR);
		}
		return url;
	}
}
